﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;

namespace 帆板仪表盘
{
    public class Mod : INotifyPropertyChanged
    {
        private double angle;
        private double power;
        private long  time;
        /// <summary>
        ///角度
        /// </summary>


        public long Count
        {
            get { return time; }
            set
            {
                time = value;
                OnPropertyChanged("Mod");
            }
        }
        public double Angle
        {
            get { return angle; }
            set { angle = value; OnPropertyChanged("PlotModel"); }
        }

        public double Power
        {
            get { return power; }
            set { power = value; OnPropertyChanged("PlotModel"); }
        }
        public Mod() { }
        public Mod(double  a, double p, long t)
        {
            Angle = a;
            Power = p;
            Count = t;
        }
        public Mod(string dataIn,long  t)
        {
            Count = t;
            Deal(dataIn);
        }
        private void Deal(string dataIn)
        {
            /*此处需要长度处理，待写*/
            // int index= dataIn.LastIndexOf("\r\n");
            if (dataIn.Length<10)
            {
                return;
            }
            try
            {

                var powers = Regex.Matches(dataIn, @"power:[0-9]+");
                power = Double.Parse(powers[powers.Count - 1].ToString().Substring(6));
            var angles = Regex.Matches(dataIn, @"角度:[0-9]+.?[0-9]+");
            angle = Double.Parse(angles[angles.Count - 1].ToString().Substring(3));
            }
            catch 
            {
            }
        

        }

        

        public event PropertyChangedEventHandler PropertyChanged;


        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));

        }
    }
}
